package org.michaelrenaud.pathfinder.client.event;

import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.EventHandler;
import org.michaelrenaud.pathfinder.shared.model.Character;
import org.michaelrenaud.pathfinder.shared.model.StatBlock;

import com.google.gwt.event.shared.HasHandlers;

public class CharacterChangeEvent extends GwtEvent<CharacterChangeEvent.CharacterChangeHandler> {

	public static Type<CharacterChangeHandler> TYPE = new Type<CharacterChangeHandler>();
	private Character character;
	private StatBlock statBlock;

	public interface CharacterChangeHandler extends EventHandler {
		void onCharacterChange(CharacterChangeEvent event);
	}

	public CharacterChangeEvent(Character character, StatBlock statBlock) {
		this.character = character;
		this.statBlock = statBlock;
	}

	public Character getCharacter() {
		return character;
	}
	
	public StatBlock getStatBlock() {
		return statBlock;
	}

	@Override
	protected void dispatch(CharacterChangeHandler handler) {
		handler.onCharacterChange(this);
	}

	@Override
	public Type<CharacterChangeHandler> getAssociatedType() {
		return TYPE;
	}

	public static Type<CharacterChangeHandler> getType() {
		return TYPE;
	}

	public static void fire(HasHandlers source, Character character, StatBlock statBlock) {
		source.fireEvent(new CharacterChangeEvent(character, statBlock));
	}
}
